﻿using System;
using System.Collections.Generic;
using System.Linq;

namespace TradeHelp.Utilities
{
    /// <summary>
    /// 
    /// </summary>
    public static class Invariant
    {
        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="arg"></param>
        /// <param name="argName"></param>
        public static void CheckIsNull<T>(T arg, string argName)
        {
            if (arg == null)
                throw new ArgumentNullException(argName);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="arg"></param>
        /// <param name="argName"></param>
        public static void CheckIsNullOrEmpty<T>(IEnumerable<T> arg, string argName)
        {
            if (arg == null || arg.Count() == 0)
                throw new ArgumentNullException(argName);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="argName"></param>
        public static void CheckIsNullOrEmpty(string arg, string argName)
        {
            if (String.IsNullOrEmpty(arg))
                throw new ArgumentException(argName);
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="arg"></param>
        /// <param name="argName"></param>
        /// <param name="chars"></param>
        public static void CheckIsNullOrEmpty(string arg, string argName, char[] chars)
        {
            CheckIsNullOrEmpty(arg, argName);
            if(String.IsNullOrEmpty(arg.Trim(chars)))
                throw new ArgumentException(argName);
        }
    }
}